package cake.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import cake.dao.CakeDao;
import cake.dao.impl.CakeDaoImpl;
import cake.entity.Cake;

@WebServlet("/admin/commentGetCake")
public class AdminCommentGetCakeServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("text/plain; charset=UTF-8");
		String sid = req.getParameter("id");
		if(sid!=null && sid!="") {
			int id = Integer.parseInt(sid);
			CakeDao cakeDao = new CakeDaoImpl();
			List<Cake> cakes = cakeDao.getCakeByCategoryId(id);
			Gson gson = new Gson();
			String json = gson.toJson(cakes);
			resp.getWriter().write(json);
		}
	}
	
}
